/*
 * Copyright (c) 2019. ascend 版权所有禁止转载。
 */

package cn.edu.zua.demo13.jpa;

import cn.edu.zua.demo13.base.BaseRepository;
import cn.edu.zua.demo13.entity.TestUserEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 说明：
 *
 * @author ascend
 * 2019/1/28 10:34
 */
@Repository
@Transactional(rollbackFor = Exception.class)
public interface TestUserJpa extends BaseRepository<TestUserEntity, Long> {
    /**
     * 适用注解自定义sql
     * @param age 年龄
     * @return 所有大于指定年龄的用户
     */
    @Query(value = "SELECT * from test_user where age > ?1", nativeQuery = true)
    List<TestUserEntity> nativeQuery(int age);

    /**
     * 删除用户
     * @param userName String
     * @param userPassword String
     */
    @Modifying
    @Query(value = "delete from test_user where user_name=?1 and user_password=?2", nativeQuery = true)
    void deleteWhere(String userName, String userPassword);
}
